﻿Public Class FormMacro
    'Public oColCode As New ClassColMacros
    Public OldName As String
    Private BackupProjet As New ClassProjet
    Private ColDocuments As New System.Collections.Generic.Dictionary(Of String, ClassDocument)

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        FormBrowser.WebBrowser1.DocumentText = My.Resources.AutomationHelp
        FormBrowser.Show()
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Call Commun.VBScriptHelp()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If (Me.TextBoxTitre.Text <> "") And (Me.TextBoxCode.Text <> "") Then
             If (Me.TextBoxTitre.Text <> Me.OldName) And (Form1.ProjetCourant.ColCode.Contains(Me.TextBoxTitre.Text)) Then
                MsgBox("Le titre " & Me.TextBoxTitre.Text & " est déjà utilisé par une autre macro!", MsgBoxStyle.Exclamation)
                Exit Sub
            End If
            Me.DialogResult = Windows.Forms.DialogResult.OK
            Me.Close()
        Else
            MsgBox("Titre et code obligatoire", MsgBoxStyle.OkOnly Or MsgBoxStyle.Exclamation)
        End If
    End Sub

    Private Sub ButtonExecuter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonExecuter.Click
        Dim oMacro As New ClassMacro
        oMacro.Titre = Me.TextBoxTitre.Text
        oMacro.Code = Me.TextBoxCode.SelectedText
        If oMacro.Code = "" Then oMacro.Code = Me.TextBoxCode.Text
        oMacro.Execute()
    End Sub

    Private Sub ButtonCopier_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonCopier.Click
        If Me.TextBoxHisto.SelectedText <> "" Then
            Me.TextBoxCode.SelectedText = vbCrLf & Me.TextBoxHisto.SelectedText()
        Else
            'On copie la ligne courante
            Me.TextBoxCode.SelectedText = vbCrLf & Me.TextBoxHisto.Lines(Me.TextBoxHisto.GetLineFromCharIndex(Me.TextBoxHisto.SelectionStart))
        End If
    End Sub

    Private Sub FormMacro_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
        Me.OldName = Me.TextBoxTitre.Text
        Me.TextBoxCode.SelectionStart = Me.TextBoxCode.Text.Length
    End Sub

    Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
        Me.TextBoxHisto.Text = ""
    End Sub

    Private Sub ComboBoxFonctions_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBoxFonctions.SelectedIndexChanged
        Me.TextBoxCode.SelectedText = Me.ComboBoxFonctions.Text
    End Sub
End Class